package com.sinothk.widget.loadingRecyclerView.demo;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sinothk.widget.loadingRecyclerView.LoadingRecyclerView;
import com.sinothk.widget.loadingRecyclerView.extend.LoadingRecycleViewHeader;

import java.util.ArrayList;

public class EmptyViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_emptyview);

        final LoadingRecyclerView mRecyclerView = this.findViewById(R.id.recyclerview);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);

//        mRecyclerView.setPullRefreshEnabled(true);
        mRecyclerView
                .getDefaultRefreshHeaderView()
                .setRefreshTimeVisible(true);

        mRecyclerView.setPullRefreshEnabled(true);

        final TextView mEmptyView = findViewById(R.id.text_empty);
        mEmptyView.setText("加载中...");
        mRecyclerView.setEmptyView(mEmptyView);

        mRecyclerView.addHeaderView(createHeardView());

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //没有数据，触发emptyView
                        ArrayList<String> listData = new ArrayList<String>();
//                        for (int i = 0; i < ; i++) {
//                            listData.add("SINNOTHK1");
//                        }
//                        listData.add("SINNOTHK2");
                        //        listData.add("SINNOTHK3");

                        MyAdapter mAdapter = new MyAdapter(listData);
                        mRecyclerView.setAdapter(mAdapter);

                        mEmptyView.setText("暂无数据...");

                        mRecyclerView.setLoadingMoreEnabled(false);
                    }
                });
            }
        }, 3000);
    }

    private View createHeardView() {
        View heardView = LoadingRecycleViewHeader.getViewByLayoutId(
                this,
                R.layout.empty_heard_view
        );
        return heardView;
    }
}
